package com.jwthhealth_pub.wristband.view.adapter;

import android.bluetooth.BluetoothDevice;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.wristband.setting.view.WristBandConnManaActivity;

import java.util.List;

/**
 * 蓝牙设备列表
 * Created by liuzhen on 2017/12/16.
 */

public class WristBandGuideDevListAdapter extends RecyclerView.Adapter {

    private final WristBandConnManaActivity mActivitiy;
    private final List<BluetoothDevice> mData;

    public WristBandGuideDevListAdapter(WristBandConnManaActivity wristBandGuideActivity, List<BluetoothDevice> devs) {
        this.mActivitiy = wristBandGuideActivity;
        this.mData = devs;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(View.inflate(mActivitiy, R.layout.item_wristbandguide_dev, null));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder vh = (ViewHolder) holder;

        final BluetoothDevice bluetoothDevice = mData.get(position);
        if (bluetoothDevice == null) return;

        vh.devName.setText(bluetoothDevice.getName());
        vh.btnConn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mActivitiy.connecBleDev(bluetoothDevice);
            }
        });


    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    private class ViewHolder extends RecyclerView.ViewHolder {

        private TextView devName;
        private Button btnConn;

        public ViewHolder(View itemView) {
            super(itemView);
            devName = itemView.findViewById(R.id.tv_wristbandguide_dev_name);
            btnConn = itemView.findViewById(R.id.btn_wristbandguide_dev_conn);
        }
    }
}
